function out = regressReturnsShortRate(data,shortRate,maturities,regime_2,h)

T             = size(data,1);
n             = length(maturities);
beta          = zeros(2,n);
R2            = zeros(1,n);
beta_tstat    = zeros(2,n);
for i=2:n
   Y              = data(1+h:T,i-1)-data(1:T-h,i);
   x              = shortRate(1:T-h,1);
   X              = [ones(T-h,1) x];
   results        = nwest(Y,X,3);
   beta(:,i)      = results.beta;           
   R2(1,i)        = results.rsqr;
   beta_tstat(:,i)= results.tstat;
end

% With regime switching
betaRegime         = zeros(4,n);
R2regime           = zeros(1,n);
betaRegime_tstat   = zeros(4,n);
for i=2:n
   Y               = data(1+h:T,i-1)-data(1:T-h,i);
   x               = shortRate(1:T-h);
   X               = [ones(T-h,1) x ...
                      regime_2(1:T-h) regime_2(1:T-h).*x  ];
   results              = nwest(Y,X,3);
   betaRegime(:,i)      = results.beta;
   R2regime(1,i)        = results.rsqr;
   betaRegime_tstat(:,i)= results.tstat;
end


% Saving the results
out.beta             = beta;
out.R2               = R2;
out.beta_tstat       = beta_tstat;
out.beta_se          = beta./beta_tstat;
out.betaRegime       = betaRegime;
out.R2regime         = R2regime;
out.betaRegime_tstat = betaRegime_tstat;
out.betaRegime_se    = betaRegime./betaRegime_tstat;
out.maturities       = maturities;